package com.kindnesslibrary.network;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * 处理Http请求，包括post，get请求
 */
public class HttpConfig {

    public static final int MSG_OK = 0x200,// 请求成功
            MSG_ERROR = 0x500,// 请求失败
            MSG_CANCEL = 0x501;// 取消
    public static final int MSG_START_DOWNLOAD = 0x600,// 开始下载
            MSG_DOWNLOAD_PROGRESS = 0x601;// 下载进度
    public static final int MSG_START_UPLOAD = 0x602,// 开始上传
            MSG_UPLOAD_PROGRESS = 0x603;// 上传进度

    private Executor executor; // 线程池处理线程
    private String ip; // 域名

    private static HttpConfig httpConfig; // 单例

    /**
     * 私有构造
     */
    private HttpConfig(){

    }

    public static HttpConfig getInstance(){
        if (httpConfig == null) {
            synchronized (HttpConfig.class) {
                if (httpConfig == null) {
                    httpConfig = new HttpConfig();
                }
            }
        }
        return httpConfig;
    }

    public void init(String ip){
        int size = Runtime.getRuntime().availableProcessors();
        executor = Executors.newFixedThreadPool(size * 4);
        this.ip = ip;
    }

    public Executor getExecutor() {
        return executor;
    }

    public String getIp() {
        return ip;
    }
}
